<template>
  <div style="width:100%;height:100%;" id="defectNumber"></div>
</template>

<script>
  const echarts = require('echarts');
  export default {
    name: 'defectNumber',
    props: {
      defectNumber: Array,
    },
    data() {
      return {};
    },
    methods: {
      init() {
        let defectNumber = this.defectNumber;
        let defectNumberMap = echarts.init(document.getElementById('defectNumber'));
        let labelOption = {
          normal: {
            show: true,
            // textBorderWidth: 2,
            color: '#2D8cF0',
          }
        };
        let option = {
          title: {
            text: '有效缺陷数',
          },
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          xAxis: [
            {
              type: 'category',
              data: ['有效SIT缺陷数' ,'有效UAT缺陷数','有效预生产缺陷数','有效生产缺陷数'],
              // boundaryGap: false,
              // splitLine: {show: false},
              // axisLabel: {show: false},
              // axisTick: {show: false},
              // axisLine: {show: false}
            }
          ],
          yAxis: [
            {
              type: 'value',
              // axisLine: {show: false},
              // axisTick: {show: false},
              axisLabel: {
                formatter: '{value}'
              },
            }
          ],
          grid: {
            left:'12%',
            top: '20%',
            bottom: '20%'
          },
          series: [
            {
              name: '有效缺陷数',
              type: 'line',
              label: labelOption,
              areaStyle: {
                normal: {
                  color: '#2D8cF0',
                },
              },
              itemStyle: {
                normal: {
                  color:'#2D8cF0',
                }
              },
              data: [
                {
                  value: defectNumber.datEffectSum
                },{
                  value: defectNumber.uatEffectSum
                },{
                  value: defectNumber.preEffectSum
                },{
                  value: defectNumber.prdEffectSum
                },
              ]
            }
          ]
        };
        defectNumberMap.setOption(option);
        window.addEventListener('resize', function () {
          defectNumberMap.resize();
        });
        defectNumberMap.on('click', (params) => {
          this.$Message.info(params.name+'的'+params.seriesName+'为：'+params.value)
        });
      }
    },
    watch: {
      defectNumber: {
        handler() {
          this.init()
        },
        deep: true
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.init()
      });
    }
  };
</script>

<style scoped>

</style>
